package utils;

import org.apache.commons.lang.StringUtils;

public abstract class AbstractCreateStmtBuilder {


	protected static final String DEFAULT_TABLE = "apple";
	protected StringBuilder builder = new StringBuilder();
	protected final boolean lineBreakMode;

	public AbstractCreateStmtBuilder(final boolean lineBreakMode) {
		this.lineBreakMode = lineBreakMode;
		createTable(DEFAULT_TABLE);
	}
	private void createTable(final String tableName) {
		builder.append("CREATE TABLE " + tableName + " ");
		buildStartOfColumns();
	}

	private void buildStartOfColumns() {
		if (lineBreakMode) {
			builder.append("\n");
		}

		builder.append("(");

	}

	public void createColumn() {
		builder.append("blah_column integer, ");

		if (lineBreakMode) {
			builder.append("\n");
		}
	}

	public void createColumnWithForeignKey(final String referencedTable) {
		builder.append("blah_column integer references " + referencedTable + "(SID), ");

		if (lineBreakMode) {
			builder.append("\n");
		}
	}

	public String build() {
		String builtString = StringUtils.chomp(builder.toString(), ", ");
		return builtString.concat(");");
	}
}
